package com.hubu.blog.utils;

import com.hubu.blog.constant.ResponseCode;
import com.hubu.blog.entity.response.PageResult;
import com.hubu.blog.entity.response.Result;

public class ResponseUtils {

    public static <T> Result<T> success(T data) {
        return Result.<T>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .message(ResponseCode.SUCCESS.getMessage())
                .data(data)
                .build();
    }

    public static <T> Result<PageResult<T>> success(PageResult<T> pageResult) {
        return Result.<PageResult<T>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .message(ResponseCode.SUCCESS.getMessage())
                .data(pageResult)
                .build();
    }

    public static <T> Result<T> error(ResponseCode responseCode) {
        return Result.<T>builder()
                .code(responseCode.getCode())
                .message(responseCode.getMessage())
                .build();
    }

    public static <T> Result<T> error(int code, String message) {
        return Result.<T>builder()
                .code(code)
                .message(message)
                .build();
    }
}